<template>
  <div class="app-container">
    <el-card shadow="never" v-loading="loading">
      <el-row :gutter="5">
        <el-col :span="24" class="main-card-view">
          <el-row>
            <el-card shadow="never" class="top-search-view-card">
              <el-row>
                <el-form :inline="true" :model="searchForm" class="demo-form-inline search-view">
                  <el-form-item label="用户名">
                    <el-input v-model="searchForm.approvalPro" placeholder="请输入用户名称"></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="handleSearch" class="search-button">查询</el-button>
                    <!--                                        <el-button type="success" @click="handleReset" class="reset-button">重置</el-button>-->
                    <el-button type="primary" @click="showCreateDialog" class="new-button">添加</el-button>
                    <el-button type="primary" @click="$router.go(-1)" class="new-button">返回</el-button>
                  </el-form-item>
                </el-form>
              </el-row>
            </el-card>
          </el-row>
          <el-row>
            <el-card shadow="never">
              <el-table :data="tableData" :stripe="true" style="width: 100%">
                <el-table-column prop="approvalPro" align="center" label="用户名" />
                <el-table-column prop="logName" align="center" label="登陆账户" />
                <el-table-column prop="role" align="center" label="角色" />
                <el-table-column prop="telPhone" align="center" label="联系电话" />
                <el-table-column prop="region" align="center" label="区域" />
                <el-table-column align="center" label="操作" width="200">
                  <template slot-scope="scope">
                    <el-button type="text" class="table-delete-btn"
                      @click="handleDelete(scope.$index, scope.row)"></el-button><!--删除-->
                  </template>
                </el-table-column>
              </el-table>
              <XPagination ref="pageInfo" :total="total" :get-data="getList" />
            </el-card>
          </el-row>
        </el-col>
      </el-row>
    </el-card>

    <el-dialog title="选择审批人" :visible.sync="dialogVisible" width="80%">
      <personnel @getName="getName"></personnel>
    </el-dialog>
  </div>
</template>

<script>
import XPagination from "../../components/xpagination/XPagination";
import * as ApprovalConfig from "../../api/expertApprovalConfig"
import personnel from '../../components/expertPersonnel.vue'
export default {
  components: { XPagination ,personnel},
  data () {
    return {
      searchForm: {
        roleName: ""
      },
      tableData: [],
      loading: false,
      dialogVisible: false,
      treeDialog: false,
      total: 0,
      dialogTitle: "添加角色",
      form: {
      },
      editStatus: "add",
      formRules: {
        roleName: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        description: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
      },
      checkedArr: [],
      defaultProps: {
        children: 'children',
        label: 'columnName'
      },
      roleId: '',
    }
  },
  methods: {
    getList (pageInfo) {
      const param = {
        ...this.searchForm,
        ...pageInfo
      }
      ApprovalConfig.queryPublisher(param).then(response => {
        console.log(response)
        this.tableData = response.data.data.rows
        this.total = response.data.data.total
        this.loading = false
      }).catch(error => {
        console.log(error)
      })
    },
    handleDelete (index, data) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          uid: data.uid,
        }
        this.loading = true
        ApprovalConfig.delPublisher(param).then(result => {
          this.loading = false
          this.$message.success(result.data.msg)
          this.handleSearch()
        }).catch(error => {
          this.loading = false
          console.log(error)
        })
      }).catch(() => {
        console.log('取消删除')
      });
    },
    handleSearch () {
      this.$refs.pageInfo.loadData()
    },
    showCreateDialog () {
      this.dialogVisible = true;
    },
    getName (msg) {
      this.dialogVisible = false;
      const param = {
        approvalSetUid:this.searchForm.approvalSetUid,
        approvalPro:msg.userName,
        approvalProUid:msg.uid,
        logName:msg.logName,
        role:msg.roleName,
        telPhone:msg.telephone,
        region:msg.region
      }
      ApprovalConfig.addPublisher(param).then(result => {
          this.$message.success(result.data.msg)
          this.handleSearch()
        }).catch(error => {
          console.log(error)
        })
    },
  },
  mounted () {
    this.searchForm.approvalSetUid = this.$route.query.uid
    this.count = this.$route.query.count
    this.handleSearch()
  }
}
</script>

<style scoped lang="scss"></style>
